// Agent usp in project jason-team-2010
!decidetarget.

+?pos(X, Y, S)
  <- .wait({+pos(X,Y,S)}).
  
+?gsize(W,H)
  <- .wait({+gsize(W,H)}).
+!decidetarget
  : cow (_,X,Y)
  <- .print("I'm looking to a COW!!!");
     -+target(X,Y).
   
+!decidetarget
  : true
  <- ?pos(OX,OY,_);
  	 jia.random2(OX,OY,NX,NY); //só pra visualizar o que está fazendo
     -+target(NX,NY).
  
+target(NX,NY)
  :  not jia.obstacle(NX,NY) &
     not jia.fence(NX,NY) &
     not jia.corral(NX,NY)  
  <- .drop_desire(move);
     jia.set_target(NX,NY); 
     !!move.
+target(NX,NY)
  : true
  <- !decidetarget. 
+!move
  :  pos(X,Y,_) &
     target(X,Y)
  <- !decidetarget.
+!move 
    : pos(X,Y,_) & 
      target(BX,BY) & 
      jia.direction(X, Y, BX, BY, D) // jia.direction finds one action D (using A*) towards the target
   <- do(D);  // this action will "block" the intention until it is sent to the simulator (in the end of the cycle)
      !!move. // continue moving
  
     